package com.wb.web.controller.customer;

import com.wb.common.core.controller.BaseController;
import com.wb.common.core.domain.AjaxResult;
import com.wb.common.core.domain.Result;
import com.wb.common.core.domain.model.LoginUser;
import com.wb.common.core.page.TableDataInfo;
import com.wb.common.vo.CustomerModelVO;
import com.wb.common.vo.SalesmanRankingVO;
import com.wb.common.vo.SalesmanStatisticVO;
import com.wb.common.vo.ShareStatisticVO;
import com.wb.system.domain.Customer;
import com.wb.system.service.ICustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 慧尔股份
 *
 * @Description TODO
 * @Author zhangxl
 * @Date 2025/7/19 15:01
 */
@RestController
@RequestMapping("customers")
@Api(tags = "客户管理")
public class CustomerController extends BaseController {


    @Autowired
    private ICustomerService customerService;

    @GetMapping("/listMy")
    @ApiOperation("客户列表(业务员)")
    public TableDataInfo customerMy(CustomerModelVO customerModelVO){
        startPage();
        LoginUser loginUser = getLoginUser();
        customerModelVO.setShareUserId(loginUser.getUserId());
        List<Customer> customerList = customerService.customerList(customerModelVO);
        return getDataTable(customerList);
    }

    @GetMapping("/list")
    @ApiOperation("客户列表（管理员）")
    public TableDataInfo customerList(CustomerModelVO customerModelVO){
        startPage();
        LoginUser loginUser = getLoginUser();
        //customerModelVO.setShareUserId(loginUser.getUserId());
        List<Customer> customerList = customerService.customerList(customerModelVO);
        return getDataTable(customerList);
    }

    @PostMapping("/add")
    @ApiOperation("客户创建")
    public AjaxResult add(@RequestBody Customer customer){
        customerService.saveCustomer(customer);
        return AjaxResult.success();
    }

    @PostMapping("/update")
    @ApiOperation("修改客户/更新客户状态")
    public AjaxResult update(@RequestBody Customer customer){
        customerService.updateCustomer(customer);
        return AjaxResult.success();
    }

    @PostMapping("/getCusomer")
    @ApiOperation("查询客户详情")
    public AjaxResult getCustomer(Long customerId){
        return AjaxResult.success(customerService.getCustomer(customerId));
    }

    @GetMapping("/todayNewAdditions")
    @ApiOperation("今日新增")
    public AjaxResult todayNewAdditions(){
        return AjaxResult.success(customerService.todayNewAdditions());
    }

    @GetMapping("/salesmanRanking")
    @ApiOperation("业务员排行")
    public AjaxResult salesmanRanking(){
        return AjaxResult.success("操作成功",customerService.salesmanRanking());
    }


    @GetMapping("/shareStatistic")
    @ApiOperation("分享统计(管理员)")
    public AjaxResult shareStatistic(){
        return AjaxResult.success("操作成功",customerService.shareStatistic());
    }

    @GetMapping("/customerConversion")
    @ApiOperation("客户转化（管理员）")
    public AjaxResult customerConversion(){
        return AjaxResult.success("操作成功",customerService.customerConversion());
    }

    @GetMapping("/salesmanStatistic")
    @ApiOperation("业务员")
    public AjaxResult salesmanStatistic(){
        //SalesmanStatisticVO salesmanStatisticVO = customerService.salesmanStatistic();
        return AjaxResult.success("操作成功",customerService.salesmanStatistic());
    }

}
